// pages/event/reporting/reportingdetails/evaluate/evaluate.js
import Toast from "../../../../../miniprogram_npm/@vant/weapp/toast/toast";
import Dialog from "../../../../../miniprogram_npm/@vant/weapp/dialog/dialog";

const app = getApp()
const log = new app.appLogs()
const http = new app.appHttp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        satisfied: "请评分",
        satisfiedlist: [0, 0, 0, 0, 0],
        event_id: null,
        content: "",//描述信息
        evaluation: null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            event_id: options.event_id
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    /**
     * 设置事件描述 输入框中的值
     */
    getTextareaValue: function (e) {
        this.setData({
            content: e.detail.value
        });
    },
    /**
     * 提交评价
     */
    setEvaluate: function () {
        const than = this
        if (than.data.evaluation == null) {
            Toast.fail("请选择评价满意度！")
            return
        }
        if ((than.data.evaluation === 1 || than.data.evaluation === 2) && than.data.content.length <= 0) {
            Toast.fail("请输入评价内容！")
            return
        }
        http.putJson("event/info/handle", {
            event_id: than.data.event_id,
            action: 14,
            evaluation: than.data.evaluation,
            content: than.data.content.length <= 0 ? "" : than.data.content
        }).then(res => {
            if (res.data.code == 200) {
                Toast.success(res.data.msg)
                setTimeout(res => {
                    wx.navigateBack({
                        delta: 1
                    })
                }, 1000)
            } else {
                Toast.fail(res.data.msg)
            }
        })
    },
    /**
     * 获取星星
     * @param e
     */
    getSatisfied: function (e) {
        const than = this
        const num = e.currentTarget.dataset.index;
        switch (num) {
            case 0:
                than.setData({
                    satisfiedlist: [1, 0, 0, 0, 0],
                    satisfied: "非常差",
                    evaluation: 1,
                })
                break;
            case 1:
                than.setData({
                    satisfiedlist: [1, 1, 0, 0, 0],
                    satisfied: "差",
                    evaluation: 2,
                })
                break;
            case 2:
                than.setData({
                    satisfiedlist: [1, 1, 1, 0, 0],
                    satisfied: "一般",
                    evaluation: 3,
                })
                break;
            case 3:
                than.setData({
                    satisfiedlist: [1, 1, 1, 1, 0],
                    satisfied: "满意",
                    evaluation: 4,
                })
                break;
            case 4:
                than.setData({
                    satisfiedlist: [1, 1, 1, 1, 1],
                    satisfied: "非常满意",
                    evaluation: 5,
                })
                break;
            default:
                than.setData({
                    satisfiedlist: [0, 0, 0, 0, 0],
                    satisfied: "请评分",
                    evaluation: null,
                })
        }
    }
})